<?php

namespace Addons\HelloWorld\Controller;

use Home\Controller\AddonsController;
use Org\Util\Snoopy;

class HelloWorldController extends AddonsController
{
    public function _initialize()
    {
        header("content-type:text/html; charset=utf-8");

    }
    public function index()
    {
        echo I("wgateid");
        echo "<br>";
        echo I("wxopenid");
        echo "<br>";
        echo I("verify");
        echo "<br>";
        echo "dddd";
        echo GetCurUrl();

    }

    public function in()
    {
        $time = time();
        $key = "mak";
        $sec = "13416659522";
        $ver = md5($time . $key . $sec);
        $sn = new Snoopy();
        $sn->fetch("http://api.weixingate.com/v1/weixin_account/wgate_token?weixin_account_id=388&key=mak&timestamp=$time&verify=$ver");
        $json = json_decode($sn->results, true);
        $op = $json["token"];
        $u = urldecode(addons_url("HelloWorld:HelloWorld/index"));
        $url = "http://www.weixingate.com/gate.php?back=$u";
//        echo $url;
//        dump($json);
//        echo $url;
//        $content = file_get_contents ( $url );
//		$content = json_decode ( $content, true );
//        echo $content ['wgateid'];
//        dump($content);
        $url=$this->curl_post_302("http://www.weixingate.com/gate.php?back=http://wx.gxsdxy.cn/wxjw/index.php?s=/addon/HelloWorld/HelloWorld/index.html");
echo $url;


    }

    function curl_post_302($url,$data=null) {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
        curl_setopt($ch, CURLOPT_TIMEOUT, 30);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // 获取转向后的内容
        $data = curl_exec($ch);
        $Headers = curl_getinfo($ch);
        curl_close($ch);
        if($data != $Headers){
            return $Headers["url"];
        }else{
            return false;
        }
    }
}
